<?php
class items
{
	const LOST = 0;
	const FOUND = 1;
	const BOTH = NULL;
	const PAGESIZE = 10;
	
	protected $item;
	protected $currentpage = 1;
	
	public function __construct()
	{
		$this->item = new item();
		$this->item->type = items::BOTH;
	}
	
	/* 显示物品列表 */
	public function defaultaction()
	{
		
		$items = new itemscollection($this->item);
		
		$total = $items->getcount();
		$pages = ceil($total/items::PAGESIZE);
		$current = $this->currentpage;
		$current = min(max(1, $current), $pages);
		$start = ($current-1)*items::PAGESIZE;
		$items->getwithdata($start, items::PAGESIZE);
		
		$pagenav = array(	'pages'=>$pages,
							'current'=>$current);
		
		$this->show($items, $pagenav);
	}
	
	protected function show($items, $pagenav)
	{
		echo view::show('items/show',
						array(	'type'=>$this->item->type,
								'items'=>$items,
								'pagenav'=>$pagenav));
	}
	
	/* 处理页码 */
	public function page()
	{
		$controller = lib::getitem('controller');
		@$this->currentpage = $controller->params[0];
		$this->defaultaction();
	}
	
	public function detail()
	{
		$controller = lib::getitem('controller');
		die($controller->params[0]);
	}
	
}